package ms.core.gateway.request;

import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;

import lombok.Data;
import ms.core.common.AppException;
import ms.core.common.consts.SysErr;
import ms.core.tool.JsonTool;
import ms.core.tool.StrTool;

@Data
public class UpdateRoleRequest {
	@JSONField(serialize=false)
	private long id;				// 记录Id
	private String roleName;		// 角色名称
	private String remark;			// 备注
	private int root;				// 是否主角色. 0-子角色;1-主角色
	
	public static UpdateRoleRequest getInstance(Map<String, Object> body, String sid) {
		UpdateRoleRequest role = JsonTool.objectToBean(body, UpdateRoleRequest.class);
		if (role==null)
			throw new AppException(SysErr.SYS_PARAM_ERR);

		if (role.getId()<1) throw new AppException(SysErr.SYS_PARAM_ERR, "请选择修改角色.");

		if (StrTool.isBlank(role.getRoleName()))
			throw new AppException(SysErr.SYS_PARAM_ERR, "角色名不可空");

		return role;
	}
}